<?php

use console\services\MigrateService;
use yii\db\Migration;

/**
 * Handles the creation of table `sys_role`.
 */
class m231229_144113_create_sys_role_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('sys_role', [
            'id' => $this->bigPrimaryKey(),
            'name' => $this->string(64)->defaultValue('')->null()->comment('名称'),
            'role_key' => $this->string(128)->defaultValue('')->null()->comment('标识'),
            'data_scope' => $this->tinyInteger(2)->defaultValue(0)->null()->comment('数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 4：本部门及以下数据权限）'),
            'check_strictly' => $this->char(1)->defaultValue('0')->null()->comment('是否父子关联'),
            'status' => $this->char(1)->defaultValue('1')->null()->comment('状态'),
            'list_sort' => $this->bigInteger()->defaultValue(10)->null()->comment('排序'),
            'remark' => $this->string(255)->defaultValue('')->null()->comment('备注'),
            'create_time' => $this->bigInteger()->defaultValue(0)->null()->comment('创建时间'),
            'update_time' => $this->bigInteger()->defaultValue(0)->null()->comment('更新时间'),
        ], MigrateService::createTableOptions('角色表'));

        $this->insert('sys_role', [
            'id' => 1, 'name' => '超级管理员', 'role_key' => 'super_admin', 'data_scope' => 1, 'check_strictly' => 1, 'status' => '1', 'list_sort' => 0
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('sys_role');
    }
}
